package com.amapv2.apis.basic;


import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;

import com.amap.api.maps.AMap;
import com.amap.api.maps.MapView;
import com.amapv2.apis.R;

/**
 * AMapV2地图中介绍如何显示一个基本地图
 * 1、mapView.onCreate(savedInstanceState);// 此方法必须重写
 * 2、生命周期的方法必须重写
 */
public class BaseMapActivvity extends Activity {

    protected String TAG;//日志的标识
    protected Context mContext;//上下文
    private MapView mapView;//Map的View
    protected AMap aMap;//AMap对象
    protected FrameLayout mFlContainer;//存放View的容器,可能有些地图页面有设置的东西，需要在这个里面增加View

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.base_map_activity);

        initParamsAndValus();

        initView(savedInstanceState);

        initMap();

        initData();
    }

    private void initParamsAndValus() {
        mContext = this;
        TAG = this.getClass().getSimpleName();
    }

    protected void initView(Bundle savedInstanceState) {
        mapView = (MapView) findViewById(R.id.map);
        mapView.onCreate(savedInstanceState);// 此方法必须重写

        mFlContainer = (FrameLayout) findViewById(R.id.fl_container);
    }

    /**
     * 初始化AMap对象
     */
    protected void initMap() {
        if (aMap == null) {
            aMap = mapView.getMap();
        }
    }

    protected void initData() {
    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onResume() {
        super.onResume();
        mapView.onResume();
    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onPause() {
        super.onPause();
        mapView.onPause();
    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mapView.onSaveInstanceState(outState);
    }

    /**
     * 方法必须重写
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();
        mapView.onDestroy();
    }

}
